﻿#region

using System.Collections.Generic;
using Lab.DataContext.DataContext;
using Lab.Server.Domain;

#endregion

namespace Lab.Server.Infrastructure {
    public class DealRepository : Repository<Deal, deal> {
        public DealRepository(IDataContext dataContext) : base(dataContext) {}

        protected override deal TranslateToDataObject(Deal domainObject) {
            var dataObject = new deal {
                                          applicant = new ApplicantRepository(DataContext)
                                              .GetApplicantDataObject(domainObject.Applicant),
                                          employer = new EmployerRepository(DataContext)
                                              .GetEmployerDataObject(domainObject.Employer),
                                          vacancy = new VacancyRepository(DataContext)
                                              .GetVacancyDataObject(domainObject.Vacancy)
                                      };
            return dataObject;
        }

        public List<Deal> GetDeals() {
            return DataContext.GetDeals().ConvertAll(TranslateToDoamain);
        }

        private Deal TranslateToDoamain(deal deal) {
            return new Deal {
                                Applicant = new ApplicantRepository(DataContext).ToDomainObject(deal.applicant),
                                Employer = new EmployerRepository(DataContext).ToDomainObject(deal.employer),
                                Vacancy = new VacancyRepository(DataContext).ToDomainObject(deal.vacancy)
                            };
        }
    }
}